<?php

namespace App\Models;


class Mutual extends Orm
{
    //
    protected $table = 'mutual';
    protected $dateFormat = 'U';
    public $timestamps = true;
    protected $casts = [
        'answer' => 'json',
    ];

    protected $appends = [
        'back_answer'
    ];

    public function courseInfo()
    {
        return $this->belongsTo(Course::class, 'course_id')->withTrashed();
    }

    public function getBackAnswerAttribute()
    {
        $array = json_decode($this->attributes['answer'], true);
        $str   = '';
        if (!empty($array)) {
            return implode('<br>', $array);
        }
        return $str;
    }
}
